<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>DOM事件监听</title>
</head>
<body>
    <input type="button" value="点击" id="btn">
    <table>
        <th>
            <td>1</td>
            <td>2</td>
            <td>3</td>
        </th>
        <tr>
            <td>1</td>
            <td>2</td>
            <td>3</td>
        </tr>
        <tr>
            <td>4</td>
            <td>5</td>
            <td>6</td>
        </tr>
        <tr>
            <td>7</td>
            <td>8</td>
            <td>9</td>
    </table>
    <script>
        document.querySelector("#btn").onclick = function() {
            alert("点击了"); 
        }
        let trs = document.querySelectorAll("tr");
        for (let i = 0; i < trs.length; i++) {
            trs[i].addEventListener("mouseenter", function() {
                    this.style.backgroundColor = "red";
            })
                
            trs[i].addEventListener("mouseleave", function() {
                this.style.backgroundColor = "gray";
            })
        }
    </script>
</body>
</html>